#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;



void GASCALCULATOR()
{
	char choice;
	double  quantity, mpg, secondary, pPrice, sPrice, formula;
	cout << " Hello and Welcome To The Gas Calculator\n"
			" --------------------------------------------\n"
			" Here you can calculate whether or not driving to\n"
			" a further gas station could save you more money\n"
			" than going to your local gas station.\n" 
			" Lets Get Started!" << endl;
	cout <<	" --------------------------------------------\n" << endl;
	cout << " ***Please enter all values numerically***\n" << endl;
	
	while (true)
	{
		cout << " Please enter the amount of gallons of gas needed: ";
		cin >> quantity;
		cout << " Enter the amount of miles per gallon your car gets: ";
		cin >> mpg;
		cout << " Enter the price of gas at your primary gas station: $";
		cin >> pPrice;
		cout << " Enter the price of gas at your secondary gas station: $";
		cin >> sPrice;
		cout << " How many miles out of the way is it for the cheaper gas?: ";
		cin >> secondary;


		formula = (quantity*pPrice) - ((quantity*sPrice) + ((secondary/mpg)*pPrice));
		cout << "\n";
		cout << " Below are the results for your query:" << endl;
		cout <<	" --------------------------------------------\n" << endl;
		if (formula < 0)
		{
			cout << " Sorry but it is not worth it to travel to the other gas station";
		}
		else 
		{
		cout << " Your savings for driving to the further gas station is: $"<< setprecision(2) << formula << endl;
		}
		cout << "\n";
		cout <<	" --------------------------------------------\n" << endl;
		cout << " Would you like to make another calculation?" << endl;
		cout << " Enter 'y' for yes and 'n' for no: ";
		cin >> choice;
		if (choice == 'y')
		{
			continue;
		}
		else 
		{
			break;
		}
		
	}


	system("pause");
}